// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: implementation of CXFormsParseSetFocus.
//   $Id$


#include "stdafx.h"
#include "parseSetFocus.h"
#include "actionsetfocus.h"
#include "ImplContextualValue.h"
#include "tags.h"

CXFormsParseSetFocus::CXFormsParseSetFocus(CImplActionSetFocus* pImpl)
	: CXFormsParseAction( pImpl)
{
	addAttributeCheck(ATTR_IDREF, &pImpl->m_sIdRef);
	m_bCheckElements = true;
}


void CXFormsParseSetFocus::CheckElement(IHTMLElement *pElem, BSTR bstrTag, CImpl* pImpl)
{
	if (wcscmp(bstrTag, L"control") == 0)
	{
		CImplContextualValue * pCV = new CImplContextualValue();
		CComVariant vtTemp;
		pElem->getAttribute(L"value",1,&vtTemp);
		if(vtTemp.vt == VT_BSTR)
			vtTemp.CopyTo(&pCV->m_sValueExpression);
		else
			 pElem->get_innerHTML(&pCV->m_sSimpleValue);
		CImplActionSetFocus * pDisp = dynamic_cast<CImplActionSetFocus*>(pImpl);
		if(pDisp)
			pDisp->m_pControlResolver = pCV;
	}
}
